<?php
require_once 'CMS/Util.php';
require_once 'CMS/Mvc/BaseController.php';
require_once 'CMS/Mvc/BaseUserController.php';
require_once 'CMS/UserCommon.php';
require_once 'CMS/Language.php';
require_once 'CMS/User.php';

//Người tạo: Nguyễn Huỳnh Đại Thành - Team 3
//Module 	: Support online
//Chức năng	: Quản lý việc hỗ trợ trực tuyến

class SupportOnline_ClickchangeSupporterController extends BaseUserController{

	public function init(){
		parent::init();
		$this->_helper->layout->disableLayout();	
	}
	
	//Chức năng show các thuộc tính hiện tại cho người dùng
	public function indexAction(){
	/*========== Start Load Language ==========*/
		$language = new Language(APPLICATION_PATH . '/widgets/supportonline');
		if(isset($_SESSION['language']))
		{
			$language_id = $_SESSION['language'];
			$tbLanguage = new Language_Model_Language();
			$name = $tbLanguage->getNameLanguage($language_id);
			$language->load($name['name']);
		}
		else
			$language->load('Default');		
		/*========== End Load Language ==========*/
			
			/*=========== Get all languages =============*/
			$all_languages = $tbLanguage->getAllLanguages();
			$languages = array();
			foreach ($all_languages as $lang){
				$languages[] = array(
									'id' 	=> $lang['language_id'],
									'name'	=> $lang['name']
									);
			}
			$this->view->languages = $languages;
		/*=========== End get ==================*/	
		/*========== Start Get Text ==============*/
		$this->view->textInfoUser 	= $language->get('text_infouser');
		$this->view->textName 		= $language->get('text_name');
		$this->view->textSave 		= $language->get('text_save');
		$this->view->textPos	 	= $language->get('text_pos');
		$this->view->textYahoo 		= $language->get('text_Yahoo');
		$this->view->textSkype 		= $language->get('text_Skype');
		$this->view->textPhone 		= $language->get('text_phone');
		$this->view->textError1 	= $language->get('text_error_6');
		$this->view->textError2 	= $language->get('text_error_7');
		$this->view->textError3 	= $language->get('text_error_8');
		$this->view->textError4 	= $language->get('text_error_9');
		$this->view->textError10 	= $language->get('text_error_10');
		$this->view->text_default 	= $language->get('text_default');
		$this->view->text_English 	= $language->get('text_English');
		$this->view->text_Vietnamese= $language->get('text_Vietnamese');
		
		/*========== End Text ==============*/
		$xmlconfig = new SimpleXMLElement($path."config.xml",null,true);//Read config.xml
		$user = new User();
		$user->init();
		$user->check_login();
		$hasmodify = $user->modifiy_widget($xmlconfig->name);
		if($hasmodify=="true")
		{
		if(isset($_GET["url"]))
			{
				$this->view->url = $_GET["url"];
			
			}
		if(isset($_GET["sp_id"]))
			$id=$_GET["sp_id"];
			$tbsupport= new SupportOnline_Model_Support();
			$supporter=$tbsupport->getSupportById($id);
			$pos = unserialize($supporter[0]["support_position"]);
			$this->view->name=$supporter[0]["support_name"];
			$this->view->pos=$pos;
			$this->view->yahoo=$supporter[0]["yahoo"];
			$this->view->skype=$supporter[0]["skype"];
			$this->view->phone=$supporter[0]["phone"];
			$this->view->id=$supporter[0]["suppord_id"];
			
		}
		else 
		{
			$this->view->error = 2 ;
		}
	}
	
	
}